package com.newear.bean;

import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

/**
 * 版本升级的JavaBean
 * Created by josan_tang on 2016/07/19.
 */
public class VersionUpgrade implements Serializable {
    private static final String TAG = "VersionUpgrade";


    /**
     * json数据解析的key,对应服务端数据库中值
     **/

    private static final String VERSION_JSONKEY = "version";
    private static final String DOWN_URL_JSONKEY = "down_url";

    private String version;   //versionname ,给程序看的，如1.0.0
    private String downUrl;  //下载链接

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getDownUrl() {
        return downUrl;
    }

    public void setDownUrl(String downUrl) {
        this.downUrl = downUrl;
    }

    /**
     * @param jsonObj
     * @return
     */
    public static boolean parseInfo(JSONObject jsonObj, VersionUpgrade versionUpgrade) {
        try {
            if (jsonObj.has(VERSION_JSONKEY)) {
                versionUpgrade.setVersion(jsonObj.optString(VERSION_JSONKEY));
            }
            if (jsonObj.has(DOWN_URL_JSONKEY)) {
                versionUpgrade.setDownUrl(jsonObj.optString(DOWN_URL_JSONKEY));
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "VersionUpgrade{" +
                "version='" + version + '\'' +
                ", downUrl='" + downUrl + '\'' +
                '}';
    }
}
